package com.zhengdongzulin.zuke.app.work.vm

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.app.data.*
import com.zhengdongzulin.zuke.base.BaseViewModel
import com.zhengdongzulin.zuke.parser.ObjectList
import com.zhengdongzulin.zuke.parser.Response
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class WorkListFragmentVm : BaseViewModel() {

    var getWorklist: StateLiveData<MutableList<WorkListBean>> = StateLiveData()

    /**
     * queryPath String	是	工单类别：待办任务，我的已办，我的发起，我的全部
     */
    fun getWorklist(queryPath: String, incidentType: String) {
        rxLifeScope.launch(
            {
                var r = RxHttp.postJson(Api.GET_GON_GDAN_LIST)
                    .add("queryPath", queryPath)
                    .add("page", mCurrentPage - 1)
                    .add("size", mPageSize)
                    .add("incidentType", incidentType)
                    .toResponse<MutableList<WorkListBean>>()
                    .await()
                getWorklist.postValueAndSuccess(r)
            }, {
                assignment(it, getWorklist)
            }
        )
    }

}